package com.xique.park.api.factory;

import com.xique.common.core.domain.R;
import com.xique.park.api.RemoteParkWxLoginService;
import com.xique.park.api.dto.AppLoginBodyDTO;
import com.xique.park.api.model.LoginParkMiniUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author shd
 * @create 2021/12/31 10:50
 */
@Component
public class RemoteParkWxLoginFallbackFactory implements FallbackFactory<RemoteParkWxLoginService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteParkWxLoginFallbackFactory.class);

    @Override
    public RemoteParkWxLoginService create(Throwable throwable) {

        log.error("停车服务调用失败:{}", throwable.getMessage());

        return new RemoteParkWxLoginService() {

            @Override
            public R<String> getPhone(String code) {
                log.error("获取微信手机号失败:" + throwable.getMessage());
                return R.fail("获取微信手机号失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginParkMiniUser> login(String phone, String code) {
                log.error("微信登录失败:" + throwable.getMessage());
                return R.fail("微信登录失败:" + throwable.getMessage());
            }
            @Override
            public R<String> getZfbPhone(String jsonStr) {
                log.error("获取支付宝手机号失败:" + throwable.getMessage());
                return R.fail("获取支付宝手机号失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginParkMiniUser> zfbLogin(AppLoginBodyDTO dto) {
                log.error("支付宝登录失败:" + throwable.getMessage());
                return R.fail("支付宝登录失败:" + throwable.getMessage());
            }

            @Override
            public R<String> sendAuthCode(String phone) {
                log.error("发送验证码失败:" + throwable.getMessage());
                return R.fail("发送验证码失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginParkMiniUser> verificationCode(String phone, String code) {
                log.error("手机验证码登录失败:" + throwable.getMessage());
                return R.fail("手机验证码登录失败:" + throwable.getMessage());
            }
        };

    }
}
